#include "memory_demo_leak.h"

#define TEST_POOL_SIZE (8*1024)
static __attribute__((aligned(4))) UINT8 g_testDynPool[TEST_POOL_SIZE];

void task_mem_leak()
{
    printf("-----task memory leak----\n");
    printf("-----before mem alloc-----\n");
    LOS_MemUsedNodeShow(g_testDynPool);
    void *ptr1 = LOS_MemAlloc(g_testDynPool, 8);
    void *ptr2 = LOS_MemAlloc(g_testDynPool, 8);
    printf("-----after mem alloc-----\n");
    LOS_MemUsedNodeShow(g_testDynPool);
}
UINT32 memory_entry_leak(void)
{
    uint32_t ret, tid;
    
    // 初始化内存池
    ret = LOS_MemInit(g_testDynPool, TEST_POOL_SIZE);
    if (LOS_OK  == ret) { printf("Mem init success!\n"); }
    else { printf("Mem init failed!\n"); return; }

    TSK_INIT_PARAM_S param = {0};
    param.pfnTaskEntry = (TSK_ENTRY_FUNC)task_mem_leak;
    param.uwStackSize  = 0x1000;
    param.pcName       = "task_mem_leak";
    param.usTaskPrio   = 10;
    // 锁住任务调度，防止高优先级任务调度
    LOS_TaskLock();
    // 创建任务
    ret = LOS_TaskCreate(&tid, &param);
    if (ret != LOS_OK) {
        printf("task memory leak create failed, errno = 0x%x\n", ret);
    }
    // 解锁任务调度
    LOS_TaskUnlock();
    return ret;
}